package com.maomao.maomaochong_i.guowuche;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;

import com.maomao.maomaochong_i.chuangZhi.GuoWu;
import com.maomao.maomaochong_i.adapterPackage.GuoWuChe;
import com.maomao.maomaochong_i.chuangZhi.GuoWuShuJu;
import com.maomao.maomaochong_i.dataBean.GridItem;
import com.maomao.maomaochong_i.adapterPackage.MyAdapter;
import com.maomao.maomaochong_i.R;

import java.util.ArrayList;

/**
 * Created by Mrma on 17.5.17.
 */

public class ShiJian{

    public static boolean gengxing;
    private LayoutInflater inflater;
    private ViewGroup container;

    private static ShiJian shiJian;
    private GuoWuShuJu shu;


    public static boolean getZhuanti(){
        System.out.println(gengxing);
        if(gengxing) {
            gengxing = false;
            shiJian.gengxing();
        }

        return gengxing;
    }

    public static ShiJian getOne(LayoutInflater inflater, ViewGroup container){
        if(shiJian == null)
            shiJian = new ShiJian(inflater,container);
        return shiJian;
    }
    private ShiJian(LayoutInflater inflater, ViewGroup container){
        this.inflater = inflater;
        this.container = container;

    }

    private GridView grid;

    public View getView(){
        View view =  inflater.inflate(R.layout.guowuche,container,false);
        grid = (GridView) view.findViewById(R.id.tushi);
        return view;
    }

    ArrayList<GridItem> mData = new ArrayList<>();
    private void tianjia(){

        mData.add(new GridItem(shu.getTu(),shu.getBiao(),shu.getJiage()));

        BaseAdapter mAdapter = new MyAdapter<GridItem>(mData, R.layout.guowu) {
            public void bindView(ViewHolder holder, GridItem obj) {
                holder.setImageResource(R.id.imageView3, obj.getId());
                holder.setText(R.id.biaoti, obj.getName());
            }
        };
        grid.setAdapter(mAdapter);
    }

    private void gengxing(){
        GuoWu guoWu = GuoWu.getOne();
        GuoWuChe guoWuChe = GuoWuChe.getOne(guoWu);
        shu = guoWuChe.guoWuShuJu;
        tianjia();

    }

}
